home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
gnu
/
gnulib
/
libsrc98.zoo
/
ftell.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-03-29
|
616b
|
37 lines
/* something like the origonal
* from Dale Schumacher's dLibs
*/
#include <stdio.h>
#include <unistd.h>
long
ftell(fp)
FILE *fp;
{
long rv, count = fp->_cnt, adjust = 0;
unsigned int f = fp->_flag;
if (((f & _IOREAD) && (!(f & _IOBIN)))
|| (count == 0)
|| (f & _IONBF))
{
fflush(fp);
rv = lseek(fp->_file, 0L, SEEK_CUR);
}
else
{
if (f & _IOREAD)
adjust = -count;
else if (f & (_IOWRT | _IORW))
{
if(f & _IOWRT)
adjust = count;
}
else return -1L;
rv = lseek(fp->_file, 0L, SEEK_CUR);
}
return (rv < 0) ? -1L : rv + adjust;
}